<template>
    <el-container>
        <el-header>
            <div class="right-panel-search">
                <el-date-picker v-model="search.time_range" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :value-format="'YYYY-MM-DD'"/>
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="apiObj" stripe remoteSort remoteFilter border @selection-change="selectionChange" :params="query" show-summary>
                <el-table-column type="selection" fixed width="50"></el-table-column>
                <el-table-column label="承制人" prop="apply_name" align="center" column-key="filterApply" :filters="chengFilters"></el-table-column>
                <el-table-column label="总单数" prop="order_count" align="center"></el-table-column>
                <el-table-column label="总件数" prop="total_count" align="center"></el-table-column>
                <el-table-column label="时效达标单量" prop="qualify_order" align="center"></el-table-column>
                <el-table-column label="时效达标件数" prop="qualify_count" align="center"></el-table-column>
                <el-table-column label="时效达标率(单)" prop="qualify_order_ratio" align="center"></el-table-column>
                <el-table-column label="时效达标率(件)" prop="qualify_count_ratio" align="center"></el-table-column>
            </scTable>
        </el-main>
    </el-container>
</template>

<script>
export default {
	name: 'user',
	data() {
		return {
			apiObj: this.$API.produce.schedule,
			selection: [],
			search: {
                order_no:null,
				time_range: [],
			},
            chengFilters: [],
            query:{
                time_range:[this.getStart(),this.getEnd()],
            },
		}
	},
    mounted() {
        this.getMonth()
        this.getCreate()
	},
	methods: {
        getStart(){
            const today = new Date();
            return this.getFormattedDate(new Date(today.getFullYear(), today.getMonth(), 1));
        },
        getEnd(){
            const today = new Date();
            const lastDay = new Date(today.getFullYear(), today.getMonth() + 1, 0);
            return this.getFormattedDate(lastDay);
        },
        getFormattedDate(date){
            const year = date.getFullYear();
            const month = (date.getMonth() + 1).toString().padStart(2, '0');
            const day = date.getDate().toString().padStart(2, '0');
            return `${year}-${month}-${day}`;
        },
        getMonth(){
            var today = new Date();
            var firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
            var lastDayOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 1);
            lastDayOfMonth.setDate(lastDayOfMonth.getDate() - 1);
            var formattedFirstDay = formatDate(firstDayOfMonth);
            var formattedLastDay = formatDate(lastDayOfMonth);
            function formatDate(date) {
                var year = date.getFullYear();
                var month = (date.getMonth() + 1).toString().padStart(2, '0'); // 月份从 0 开始，需要加 1
                var day = date.getDate().toString().padStart(2, '0');
                return year + '-' + month + '-' + day;
            }
            this.search.time_range[0] = formattedFirstDay
            this.search.time_range[1] = formattedLastDay
            this.query.time_range[0] = formattedFirstDay
            this.query.time_range[1] = formattedLastDay
        },
        async getCreate() {
            var res = await this.$API.all.getProduceFilter.get({process_id:3,place:2});
			let cheng = []
            res.data.supplier_list.map(item => {
                cheng.push({
                    text: item.name,
                    value: item.id,
                })
            })
			this.chengFilters = cheng
		},
		//确定操作
		async confirm(row) {
			var reqData = { id: row.id }
			var res = await this.$API.inventory.confirm.post(reqData);
			if (res.code == 1) {
                this.$refs.table.refresh()
				this.$message.success("确定成功")
			} else {
				this.$alert(res.message, "提示", { type: 'error' })
			}
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        selectionChange(selection){
            this.selection = selection;
        },
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}
</style>
